﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace CSharpAlgorithm
{
    class StoreCredit
    {
        public StoreCredit()
        {
            int testCount = Int32.Parse(Console.ReadLine());
            for (int testCase = 1; testCase <= testCount; testCase++)
            {
                int credit = Int32.Parse(Console.ReadLine());
                int itemCount = Int32.Parse(Console.ReadLine());
                string[] input = Console.ReadLine().Split(' ');
                int[,] priceMap = new int[1001, 2];
                int[] prices = new int[itemCount];
                for (int i = 0; i < itemCount; i++)
                {
                    int price = Int32.Parse(input[i]);
                    if (priceMap[price, 0] == 0)
                    {
                        priceMap[price, 0] = i + 1;
                    }
                    else
                    {
                        priceMap[price, 1] = i + 1;
                    }
                    prices[i] = price;
                }
                for (int i = 0; i < itemCount; i++)
                {
                    int need = credit - prices[i];
                    if (need > 0 && need <= 1000 && priceMap[need, 0] > 0)
                    {
                        if (i + 1 == priceMap[need, 0])
                        {
                            if (priceMap[need, 1] > 0)
                            {
                                Console.WriteLine("Case #" + testCase + ": " + (i + 1) + " " + priceMap[need, 1]);
                                break;
                            }
                        }
                        else
                        {
                            Console.WriteLine("Case #" + testCase + ": " + (i + 1) + " " + priceMap[need, 0]);
                            break;
                        }
                    }
                }
            }
        }
    }
}
